package com.emasdemo.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory;
import com.emasdemo.R;

public class DeviceActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_device);
        initBar();
        TextView deviceid = (TextView)this.findViewById(R.id.deviceid_getdeviceid);

        if (null == PushServiceFactory.getCloudPushService()) {
            deviceid.setText("SDk环境初始化失败");
        } else {
            deviceid.setText("您的 DeviceID 为 ：" + "\n" + PushServiceFactory.getCloudPushService().getDeviceId());
            Log.i("DeviceId:",deviceid.getText().toString());
        }
    }

    /**
     * 用于其他Activty跳转到该Activity
     * @param context
     */
    public static void actionStart(Context context) {
        Intent intent = new Intent(context, DeviceActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    private void initBar() {
        findViewById(R.id.bar_img).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DeviceActivity.this.finish();
            }
        });

        ((TextView)findViewById(R.id.bar_text)).setText("设备DeviceID");
    }
}
